package cn.xenosp.server.config;

import cn.xenosp.server.common.cache.Cache;
import cn.xenosp.server.common.filter.RequestVerifyFilter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 项目名： service-web
 * 包路径： cn.xenosp.server.config
 * 作者：   TongHui
 * 创建时间: 2024-08-25 13:37
 * 描述: TODO
 * 版本: 1.0
 */
@Slf4j
@Configuration
public class FilterConfig {

    @Autowired
    Cache redisCache;

    @Bean
    public FilterRegistrationBean<RequestVerifyFilter> registFilter() {
        FilterRegistrationBean<RequestVerifyFilter> registration = new FilterRegistrationBean();
        RequestVerifyFilter requestVerifyFilter = new RequestVerifyFilter();
        requestVerifyFilter.setRedisCache(redisCache);
        registration.setFilter(requestVerifyFilter);
        registration.addUrlPatterns("/*");
        registration.setName("LoginFilter");
        registration.setOrder(1);
        return registration;
    }
}
